home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / ansi.c next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  249 lines

  1. /*
  2.  * The routines in this file provide support for ANSI style terminals
  3.  * over a serial line. The serial I/O services are provided by routines in
  4.  * "termio.c". It compiles into nothing if not an ANSI device.
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     ANSI
  14.  
  15. #if    AMIGA
  16. #define NROW    23                      /* Screen size.                 */
  17. #define NCOL    77                      /* Edit if you want to.         */
  18. #else
  19. #define NROW    25                      /* Screen size.                 */
  20. #define NCOL    80                      /* Edit if you want to.         */
  21. #endif
  22. #define    NPAUSE    100            /* # times thru update to pause */
  23. #define    MARGIN    8            /* size of minimim margin and    */
  24. #define    SCRSIZ    64            /* scroll size for extended lines */
  25. #define BEL     0x07                    /* BEL character.               */
  26. #define ESC     0x1B                    /* ESC character.               */
  27.  
  28. extern  int     ttopen();               /* Forward references.          */
  29. extern  int     ttgetc();
  30. extern  int     ttputc();
  31. extern  int     ttflush();
  32. extern  int     ttclose();
  33. extern  int     ansimove();
  34. extern  int     ansieeol();
  35. extern  int     ansieeop();
  36. extern  int     ansibeep();
  37. extern  int     ansiopen();
  38. extern    int    ansirev();
  39. extern    int    ansiclose();
  40. extern    int    ansikopen();
  41. extern    int    ansikclose();
  42. extern    int    ansicres();
  43.  
  44. #if    COLOR
  45. extern    int    ansifcol();
  46. extern    int    ansibcol();
  47.  
  48. int    cfcolor = -1;        /* current forground color */
  49. int    cbcolor = -1;        /* current background color */
  50. #endif
  51.  
  52. /*
  53.  * Standard terminal interface dispatch table. Most of the fields point into
  54.  * "termio" code.
  55.  */
  56. TERM    term    = {
  57.     NROW-1,
  58.         NROW-1,
  59.         NCOL,
  60.         NCOL,
  61.     MARGIN,
  62.     SCRSIZ,
  63.     NPAUSE,
  64.         ansiopen,
  65.         ansiclose,
  66.     ansikopen,
  67.     ansikclose,
  68.         ttgetc,
  69.         ttputc,
  70.         ttflush,
  71.         ansimove,
  72.         ansieeol,
  73.         ansieeop,
  74.         ansibeep,
  75.     ansirev,
  76.     ansicres
  77. #if    COLOR
  78.     , ansifcol,
  79.     ansibcol
  80. #endif
  81. };
  82.  
  83. #if    COLOR
  84. ansifcol(color)        /* set the current output color */
  85.  
  86. int color;    /* color to set */
  87.  
  88. {
  89.     if (color == cfcolor)
  90.         return;
  91.     ttputc(ESC);
  92.     ttputc('[');
  93.     ansiparm(color+30);
  94.     ttputc('m');
  95.     cfcolor = color;
  96. }
  97.  
  98. ansibcol(color)        /* set the current background color */
  99.  
  100. int color;    /* color to set */
  101.  
  102. {
  103.     if (color == cbcolor)
  104.         return;
  105.     ttputc(ESC);
  106.     ttputc('[');
  107.     ansiparm(color+40);
  108.     ttputc('m');
  109.         cbcolor = color;
  110. }
  111. #endif
  112.  
  113. ansimove(row, col)
  114. {
  115.         ttputc(ESC);
  116.         ttputc('[');
  117.         ansiparm(row+1);
  118.         ttputc(';');
  119.         ansiparm(col+1);
  120.         ttputc('H');
  121. }
  122.  
  123. ansieeol()
  124. {
  125.         ttputc(ESC);
  126.         ttputc('[');
  127.         ttputc('K');
  128. }
  129.  
  130. ansieeop()
  131. {
  132. #if    COLOR
  133.     ansifcol(gfcolor);
  134.     ansibcol(gbcolor);
  135. #endif
  136.         ttputc(ESC);
  137.         ttputc('[');
  138.         ttputc('J');
  139. }
  140.  
  141. ansirev(state)        /* change reverse video state */
  142.  
  143. int state;    /* TRUE = reverse, FALSE = normal */
  144.  
  145. {
  146. #if    COLOR
  147.     int ftmp, btmp;        /* temporaries for colors */
  148. #endif
  149.  
  150.     ttputc(ESC);
  151.     ttputc('[');
  152.     ttputc(state ? '7': '0');
  153.     ttputc('m');
  154. #if    COLOR
  155.     if (state == FALSE) {
  156.         ftmp = cfcolor;
  157.         btmp = cbcolor;
  158.         cfcolor = -1;
  159.         cbcolor = -1;
  160.         ansifcol(ftmp);
  161.         ansibcol(btmp);
  162.     }
  163. #endif
  164. }
  165.  
  166. ansicres()    /* change screen resolution */
  167.  
  168. {
  169.     return(TRUE);
  170. }
  171.  
  172. ansibeep()
  173. {
  174.         ttputc(BEL);
  175.         ttflush();
  176. }
  177.  
  178. ansiparm(n)
  179. register int    n;
  180. {
  181.         register int q,r;
  182.  
  183.         q = n/10;
  184.         if (q != 0) {
  185.         r = q/10;
  186.         if (r != 0) {
  187.             ttputc((r%10)+'0');
  188.         }
  189.         ttputc((q%10) + '0');
  190.         }
  191.         ttputc((n%10) + '0');
  192. }
  193.  
  194. ansiopen()
  195. {
  196. #if     V7 | USG | BSD
  197.         register char *cp;
  198.         char *getenv();
  199.  
  200.         if ((cp = getenv("TERM")) == NULL) {
  201.                 puts("Shell variable TERM not defined!");
  202.                 exit(1);
  203.         }
  204.         if (strcmp(cp, "vt100") != 0) {
  205.                 puts("Terminal type not 'vt100'!");
  206.                 exit(1);
  207.         }
  208. #endif
  209.     strcpy(sres, "NORMAL");
  210.     revexist = TRUE;
  211.         ttopen();
  212. }
  213.  
  214. ansiclose()
  215.  
  216. {
  217. #if    COLOR
  218.     ansifcol(7);
  219.     ansibcol(0);
  220. #endif
  221.     ttclose();
  222. }
  223.  
  224. ansikopen()    /* open the keyboard (a noop here) */
  225.  
  226. {
  227. }
  228.  
  229. ansikclose()    /* close the keyboard (a noop here) */
  230.  
  231. {
  232. }
  233.  
  234. #if    FLABEL
  235. fnclabel(f, n)        /* label a function key */
  236.  
  237. int f,n;    /* default flag, numeric argument [unused] */
  238.  
  239. {
  240.     /* on machines with no function keys...don't bother */
  241.     return(TRUE);
  242. }
  243. #endif
  244. #else
  245. ansihello()
  246. {
  247. }
  248. #endif
  249.